package com.wrl.mmall.controller.portal;

import com.wrl.mmall.common.ServerResponse;
import com.wrl.mmall.service.IProductService;
import com.wrl.mmall.vo.ProductDetailVo;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 商品管理
 * Created by Wang Renlei on 2018/9/20.
 */
@Slf4j
@Controller
@RequestMapping("/product")
public class ProductController {


    @Autowired
    private IProductService iProductService;

    /**
     * 查看商品详情
     *
     * @param productId
     * @return
     */
    @RequestMapping("detail.do")
    @ResponseBody
    public ServerResponse<ProductDetailVo> detail(Integer productId) {
        log.info("ProductController.detail");
        return iProductService.getProductDetail(productId);
    }

    /**
     * 查看所有商品
     *
     * @param keyword    按商品名字 模糊查询
     * @param categoryId 商品id
     * @param pageNum    起始页，默认1
     * @param pageSize   一页显示的数量，默认10
     * @param orderBy    排序字段，默认空
     * @return
     */
    @RequestMapping("list.do")
    @ResponseBody
    public ServerResponse<PageInfo> list(@RequestParam(value = "keyword", required = false) String keyword,
                                         @RequestParam(value = "categoryId", required = false) Integer categoryId,
                                         @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                         @RequestParam(value = "orderBy", defaultValue = "") String orderBy) {
        log.info("ProductController.list");
        return iProductService.getProductByKeywordCategory(keyword, categoryId, pageNum, pageSize, orderBy);

    }


}
